package ink.sunflower.security.security;

import ink.sunflower.utils.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author zhaokuii11@163.com
 * @create 2022-06-05 22:23
 * @Description 密码处理
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder() {
        this(-1);
    }

    public DefaultPasswordEncoder(Integer strength) {

    }


    /**
     * 字符串进行 MD5加密
     *
     * @param charSequence
     * @return
     */
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }

    /**
     * 密码进行比对
     *
     * @param charSequence   加密之后的密码
     * @param encodePassword 传入的密码
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String encodePassword) {
        return encodePassword.equals(MD5.encrypt(charSequence.toString()));
    }
}
